package TP6;

/**
 * Created by IntelliJ IDEA.
 * User: pc
 * Date: 18/11/11
 * Time: 19:21
 * To change this template use File | Settings | File Templates.
 */
public class BinSearchArray<K, V> extends AbstractSearchArray<K, V> {

    public BinSearchArray(){
        super();
    }

    public int search(Object o, int i, int j){
        if((j-i) > 0){
            int n = (j+i)/2;
            int k = entryList.get(n).getKey().hashCode();
            if(k==o.hashCode()){
                return n;
            }else if(o.hashCode()<k){
                return search(o, i, n-1);
            }else{
                return search(o, n+1, j);
            }
        }else if(!isEmpty() && (entryList.get(i).getKey().hashCode())==(o.hashCode())){
            return i;
        }
        return -1;
    }

}
